package com.tornado.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tornado.system.model.Orders;
import com.tornado.system.service.IorderService;
import com.tornado.system.util.IntegerUtil;
import com.tornado.system.util.StringUtil;

@Controller
@RequestMapping("od")
public class orderController {
	
	@Autowired
	private IorderService orderService;
	
	@RequestMapping(value="/hh",method=RequestMethod.GET)
	public String orderList(Model model){
		
		List<Orders> List=orderService.orderList();
		model.addAttribute("orders",List);
		System.out.println("555");
		return "/orderMg/order";
	}
	
	@RequestMapping(value="/aa",method=RequestMethod.POST)
	public String orderList2(String oid,Integer uid,Model model){
		List<Orders> List=null;
		System.out.println(oid);
		String msg=null;
		
		//订单号不为空值时
		if(StringUtil.isNotEmpty(oid)){
			
			//订单号不为空 且 用户id不为空值时
			if(IntegerUtil.isNotEmpty(uid)){
				List=orderService.orderListByOrderIdUserId(oid, uid);
				
			//订单号不为空 且 用户id是空值
			}else{
				
				List=orderService.orderListByOrderId(oid);			
			}
		//订单号为空值时	 且 用户id不为空值时
		}else if(IntegerUtil.isNotEmpty(uid)){
			List=orderService.orderListByUserId(uid);
			
		//订单号为空值时	 且 用户id为空值时	
		}else{
			List=orderService.orderList();
			System.out.println("没有结果");
		}
		if(List.size()!=0){
			model.addAttribute("orders",List);
			model.addAttribute("oid",oid);
			model.addAttribute("uid",uid);
		}else{
			msg="没有找到相关结果,请确认后重新查找!";
			model.addAttribute("msg",msg);
		}
		
		//System.out.println("556");
		return "/orderMg/order";
	}
	

}